package com.zm.demo.sc.mybatisplus.service;

import com.zm.demo.sc.mybatisplus.mapper.UserMapper;
import com.zm.demo.sc.mybatisplus.po.User;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.apache.skywalking.apm.toolkit.trace.TraceCrossThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@TraceCrossThread
@Service("userService")
public class UserServiceImpl implements UserService{

    @Autowired
    UserMapper userMapper;
    Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);



//    @Trace
    @Override
    public List<User> getUsers() {
//        logger.info("start : {}", start);
        try{
//            Thread.sleep(100L);
        }catch (Exception e){
            e.printStackTrace();
        }
        long start = System.currentTimeMillis();
        List<User> users = userMapper.selectList(null);
        long end = System.currentTimeMillis();
        logger.info("{}, end : {},  cost {} ms",Thread.currentThread().getName() , end ,end - start);
        return users;
    }

    @Override
    public int updateById(User entity) {
        return userMapper.updateById(entity);
    }

    @Override
    public int updateBatch(List<User> users) {
        return userMapper.updateBatch(users);
    }

    @Override
    public int updateBatch1(List<User> users) {
        return userMapper.updateBatch1(users);
    }


}
